'''
    设计一个装饰器，可作用于任何函数上，打印函数执行时间
'''
import time
from functools import reduce

def metric(fn):
    def count(*args,**kwargs):
        StartTime = time.time()
        fn(*args,**kwargs)
        EndTime = time.time()
        print('It tooks '+str(EndTime - StartTime)+'times')
    return count

# 测试装饰器效果
@metric
def str2int(s):
    DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
    def char2num(s):
        return DIGITS[s]
    return reduce(lambda x,y:x*10+y,map(char2num,s))
print(str2int('2324'))
